﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;
using Honestysoft.Baseframework.Model;

namespace Honestysoft.Financing.WebUI.Module.Project
{
    public partial class ProjectConfirm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            txtTransactName.Enabled = false;
            txtTranTime.Enabled = false;
            BD_Project project = new Honestysoft.BaseObject.BaseBusinessLogic<BD_Project>(Globals.CurrentConnStringName).GetEntity(Request.QueryString["ID"]);
            if (project.IsInit)//已审核
            {
                txtTransactName.Text = new Honestysoft.BaseObject.BaseBusinessLogic<Sys_User>(Globals.CurrentConnStringName).GetEntity(project.ConfirmUser).UserName;
                txtTranTime.Text = project.ConfirmTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                txtOpinion.Text = project.ConfirmOpinion;
                txtOpinion.Enabled = false;
                btnOK.Enabled = false;
            }
            else
            {
                txtTransactName.Text = UserLoginer.LoginUser.Name;
                txtTranTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");                
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            bool bRet = false;
            try
            {
                bRet = new Honestysoft.Financing.BusinessLogic.Project(Globals.CurrentConnStringName).ConfirmInit(Request.QueryString["ID"], UserLoginer.LoginUser.ID, txtOpinion.Text);
                if (bRet)
                {
                    ScriptHelper.Window.AlertClose("确认初始化成功！", true);
                }
                else
                {
                    ScriptHelper.Window.Alert("确认初始化失败！");
                }
            }
            catch (Exception ex)
            {
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("确认初始化失败！\r\n" + ex.Message);
            }
        }
    }
}